Class MapBinaryHeap<T>

  • All Implemented Interfaces:
    java.lang.Iterable<T>, java.util.Collection<T>, java.util.Queue<T>

    public class MapBinaryHeap<T>
    extends java.util.AbstractCollection<T>
    implements java.util.Queue<T>
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Comparator<T> comp  
      private java.util.Vector<T> heap  
      private java.util.Map<T,​java.lang.Integer> object_indices  
      private static int TOP  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean add​(T o)  
      void clear()  
      boolean contains​(java.lang.Object o)  
      T element()  
      private void initialize​(java.util.Comparator<T> comp)  
      boolean isEmpty()  
      java.util.Iterator<T> iterator()  
      private int lChild​(int i)  
      boolean offer​(T o)  
      private int parent​(int i)  
      T peek()  
      private void percolateDown​(int cur)  
      private int percolateUp​(int cur, T o)  
      T poll()  
      private int rChild​(int i)  
      T remove()  
      boolean remove​(java.lang.Object o)  
      boolean removeAll​(java.util.Collection<?> c)  
      boolean retainAll​(java.util.Collection<?> c)  
      int size()  
      private void swap​(int i, int j)  
      void update​(T o)  
      • Methods inherited from class java.util.AbstractCollection

        addAll, containsAll, toArray, toArray, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        addAll, containsAll, equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray, toArray, toArray
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Field Detail

      • heap

        private java.util.Vector<T> heap
      • object_indices

        private java.util.Map<T,​java.lang.Integer> object_indices
      • comp

        private java.util.Comparator<T> comp
    • Constructor Detail

      • MapBinaryHeap

        public MapBinaryHeap​(java.util.Comparator<T> comp)
      • MapBinaryHeap

        public MapBinaryHeap()
      • MapBinaryHeap

        public MapBinaryHeap​(java.util.Collection<T> c)
      • MapBinaryHeap

        public MapBinaryHeap​(java.util.Collection<T> c,
                             java.util.Comparator<T> comp)
    • Method Detail

      • initialize

        private void initialize​(java.util.Comparator<T> comp)
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<T>
        Overrides:
        clear in class java.util.AbstractCollection<T>
      • add

        public boolean add​(T o)
        Specified by:
        add in interface java.util.Collection<T>
        Specified by:
        add in interface java.util.Queue<T>
        Overrides:
        add in class java.util.AbstractCollection<T>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<T>
        Overrides:
        isEmpty in class java.util.AbstractCollection<T>
      • peek

        public T peek()
        Specified by:
        peek in interface java.util.Queue<T>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<T>
        Specified by:
        size in class java.util.AbstractCollection<T>
      • update

        public void update​(T o)
      • contains

        public boolean contains​(java.lang.Object o)
        Specified by:
        contains in interface java.util.Collection<T>
        Overrides:
        contains in class java.util.AbstractCollection<T>
      • percolateDown

        private void percolateDown​(int cur)
      • percolateUp

        private int percolateUp​(int cur,
                                T o)
      • lChild

        private int lChild​(int i)
      • rChild

        private int rChild​(int i)
      • parent

        private int parent​(int i)
      • swap

        private void swap​(int i,
                          int j)
      • iterator

        public java.util.Iterator<T> iterator()
        Specified by:
        iterator in interface java.util.Collection<T>
        Specified by:
        iterator in interface java.lang.Iterable<T>
        Specified by:
        iterator in class java.util.AbstractCollection<T>
      • remove

        public boolean remove​(java.lang.Object o)
        Specified by:
        remove in interface java.util.Collection<T>
        Overrides:
        remove in class java.util.AbstractCollection<T>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<T>
        Overrides:
        removeAll in class java.util.AbstractCollection<T>
      • retainAll

        public boolean retainAll​(java.util.Collection<?> c)
        Specified by:
        retainAll in interface java.util.Collection<T>
        Overrides:
        retainAll in class java.util.AbstractCollection<T>
      • element

        public T element()
                  throws java.util.NoSuchElementException
        Specified by:
        element in interface java.util.Queue<T>
        Throws:
        java.util.NoSuchElementException
      • offer

        public boolean offer​(T o)
        Specified by:
        offer in interface java.util.Queue<T>
      • poll

        public T poll()
        Specified by:
        poll in interface java.util.Queue<T>
      • remove

        public T remove()
        Specified by:
        remove in interface java.util.Queue<T>